package com.itheima.app.controller;

import com.itheima.app.interceptor.UserHolder;
import com.itheima.app.manager.SettingManager;
import com.itheima.domain.db.Notification;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import java.util.Map;

@RestController
public class SettingController {

    @Autowired
    private SettingManager settingManager;

    //用户通用设置 - 读取
    @GetMapping("/users/settings")
    public ResponseEntity findSettings() {
//        System.out.println(" 用户通用设置 - 读取");
        return settingManager.findSettings();
    }

    //设置问题
    @PostMapping("/users/questions")
    public ResponseEntity saveOrUpdateQuestions(@RequestBody
                                                        Map<String, String> map) {
        String content = map.get("content");
//        System.out.println("进入saveOrUpdateQuestions");
//        System.out.println("评论为"+content);
        return settingManager.saveOrUpdateQuestions(content);

    }

    //三个设置
    @PostMapping("/users/notifications/setting")
    public ResponseEntity saveOrUpdateNotifications(@RequestBody
                                                            Notification notification) {
//        System.out.println("UserHolder.getLocal()---"+UserHolder.getLocal());
//        System.out.println("notification---"+notification);
        return settingManager.saveOrUpdateNotifications(notification);

    }

    //黑名单查询
    @GetMapping("/users/blacklist")
    public ResponseEntity findBlacklist(
            @RequestParam(defaultValue = "1") Integer page,
            @RequestParam(defaultValue = "10") Integer pagesize) {
        System.out.println("进入黑名单查询");
        return settingManager.findBlacklist(page, pagesize);
    }

    @DeleteMapping("/users/blacklist/{blackUserId}")
    public ResponseEntity deleteBlackUser(@PathVariable Long blackUserId) {

        return settingManager.deleteBlackUser(blackUserId);
    }


}
